package com.tj.pystandard.tjapi.teacher.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tj.pystandard.tjapi.common.config.RedisCacheAspect;
import com.tj.pystandard.tjapi.common.vo.PageResDTO;
import com.tj.pystandard.tjapi.common.vo.PageVO;
import com.tj.pystandard.tjapi.common.vo.ResponseVo;
import com.tj.pystandard.tjapi.common.vo.UserResVO;
import com.tj.pystandard.tjapi.teacher.dao.UserMapper;
import com.tj.pystandard.tjapi.teacher.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @author tangjing
 * @date 2021/09/30 16:26
 */
@RestController
@RequestMapping("/api")
@Api(tags = "api接口")
@Slf4j
public class TestOneController {

    @Resource
    private TeacherService teacherService;

    @Resource
    private UserMapper userMapper;

    @PostMapping("/test")
    @ApiOperation(value = "查询简单输出")
    public ResponseVo<String> pageBanner() {
        return teacherService.serviceOne();
    }

    @PostMapping("/useOther")
    @ApiOperation(value = "使用其他服务")
    public ResponseVo<String> userOther() {
        return teacherService.serviceTwo();
    }

    @PostMapping("pageUser")
    @RedisCacheAspect(dir = "user")
    @ApiOperation(value = "查询用户列表")
    public ResponseVo<PageResDTO<UserResVO>> pageUser(@RequestBody @Valid PageVO reqVO){
        PageHelper.startPage(reqVO.getPageNum(),reqVO.getPageSize());
        List<UserResVO> result= userMapper.pageUser();
        PageInfo<UserResVO> pageInfo = new PageInfo<>(result);
        return new ResponseVo<>(new PageResDTO<>(pageInfo.getTotal(),pageInfo.getList()));

    }


}
